package controller.webservice.bootstrap;

import java.io.IOException;

import manager.SectionMgr;
import controller.validator.SectionValidator;
import exception.InputValidationErrors;

/**
 * Validates and loads section CSV.
 * 
 * @author huangjm.2012, jaslin.wee.2012, sheryl.tay.2012
 * 
 */
public class SectionCsvLoader extends CsvLoader {

	private SectionMgr sectionMgr;

	SectionCsvLoader(String pathToFile) throws IOException {
		super(pathToFile);
		sectionMgr = new SectionMgr();
	}

	@Override
	boolean loadRow() throws InputValidationErrors {
		String courseCode = getValue("course");
		String sectionCode = getValue("section");
		String dayStr = getValue("day");
		String startTime = getValue("start");
		String endTime = getValue("end");
		String sizeStr = getValue("size");
		String instructor = getValue("instructor");
		String venue = getValue("venue");

		SectionValidator validator = new SectionValidator(courseCode,
				sectionCode, dayStr, startTime, endTime, instructor, venue,
				sizeStr);
		validator.performValidationBeforeAdding();

		return sectionMgr.addSection(validator.getSection());
	}

}
